function fun() {
    let movies;
    let operas;
    let info = location.search.substr(4)
    $.ajax({
        url: 'https://www.fastmock.site/mock/bb4157f45a0b5ffdcb3f6d984517a6c0/woniuMovie/getAllMovies',
        success(data) {
            movies = data.movies;
            let movie = movies.find(movie => movie.id == info);
            moviesRender(movie);
            $(".price").text(`${movie.language}•￥${movie.price}`)
        }
    });

    $.ajax({
        url: 'https://www.fastmock.site/mock/bb4157f45a0b5ffdcb3f6d984517a6c0/woniuMovie/getAllOperas',
        success(data) {
            operas = data.operas;
            let opera = operas.filter(opera => {
                return opera.movies.some(item => item == info);
            });
            operasRander(opera);
        }
    });

    async function moviesRender(movie) {
        // 获得类型
        await $.ajax({
            url: 'https://www.fastmock.site/mock/bb4157f45a0b5ffdcb3f6d984517a6c0/woniuMovie/getAllTypes',
            success(data) {
                let types = data.types;
                let type = types.filter(item => {
                    return movie.movieType.find(i => i == item.id);
                });
                let newType = type.map(item => item.name)
                $("#type").text(newType.join(" "));
            }
        });
        $("header").css("background", `url(${movie.posterSrc})`);
        $("header").css("backgroundSize", `100%`);
        $(".movie img").prop("src", movie.imgSrc);
        $(".text ul li p").text(movie.title);


        $("#duration").text(movie.duration);
        $("#score").text(movie.score);
    }

    function operasRander(opera) {
        let newOpera = opera.map(item => 
            `<div class="m1">
                <ul>
                    <li>
                        <p class="title">${item.name}</p>
                    </li>
                    <li>
                        <p class="where"><i class="iconfont icon-Frame1"></i>54.0km•${item.address}</p>
                        <p class="price">英文2D•￥30.00</p>
                    </li>
                    <li>
                        <div class="time">
                            <div class="over">11:00</div>
                            <div class="over">13:00</div>
                            <div class="case">15:00</div>
                            <div class="case do">17:00</div>
                            <div class="case">19:00</div>
                            <div class="case">20:00</div>
                            <div class="case">21:00</div>
                        </div>
                    </li>
                </ul>
            </div>`
        );
        $("#map").html(newOpera);
    }

    $(function () {
        $('.btn').on('click', function () {
            $('#choice').find('button').attr('class', 'btn');
            $(this).attr('class', 'btn on');
            if ($(this).text() == '排片') {
                $('#choiceSeat').css('display', 'block');
                $('#introduce').css('display', 'none');
            } else if ($(this).text() == '简介') {
                $('#introduce').css('display', 'block');
                $('#choiceSeat').css('display', 'none');
            }
        });

        // 立即购票
        $(".finish").click(function () {
            location.assign(`../html/Seatse.html${location.search}`);
        });

        $("#week ul").on('click', 'li', function () {
            $(this).addClass("take").siblings().removeClass("take");
        });

        $("#map").on('click', ' .m1 ul li .time div', function () {
            if ($(this).attr("class") != "over") {
                $(this).addClass("do").siblings().removeClass("do");
            }
        });

        $("header").on('click','a',function() {
            history.back();
        })

    });
}
fun();